home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / iconext / iconextr.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  6.1 KB  |  165 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Icon Extract"
  6.    ClientHeight    =   2355
  7.    ClientLeft      =   1590
  8.    ClientTop       =   2115
  9.    ClientWidth     =   4170
  10.    Height          =   2760
  11.    Icon            =   ICONEXTR.FRX:0000
  12.    Left            =   1530
  13.    LinkMode        =   1  'Source
  14.    LinkTopic       =   "Form1"
  15.    MaxButton       =   0   'False
  16.    ScaleHeight     =   2355
  17.    ScaleWidth      =   4170
  18.    Top             =   1770
  19.    Width           =   4290
  20.    Begin PictureBox pic2 
  21.       AutoRedraw      =   -1  'True
  22.       AutoSize        =   -1  'True
  23.       Height          =   492
  24.       Left            =   2280
  25.       ScaleHeight     =   465
  26.       ScaleWidth      =   465
  27.       TabIndex        =   2
  28.       Top             =   1800
  29.       Width           =   492
  30.    End
  31.    Begin CommandButton btnCopy 
  32.       Caption         =   "Copy to picture box ->"
  33.       Height          =   372
  34.       Left            =   120
  35.       TabIndex        =   6
  36.       Top             =   1800
  37.       Width           =   2052
  38.    End
  39.    Begin HScrollBar hs 
  40.       Enabled         =   0   'False
  41.       Height          =   252
  42.       Left            =   600
  43.       TabIndex        =   1
  44.       Top             =   1440
  45.       Width           =   1212
  46.    End
  47.    Begin CommandButton Command1 
  48.       Caption         =   "Exit"
  49.       Height          =   372
  50.       Left            =   3000
  51.       TabIndex        =   7
  52.       Top             =   1080
  53.       Width           =   1092
  54.    End
  55.    Begin PictureBox pic 
  56.       AutoRedraw      =   -1  'True
  57.       AutoSize        =   -1  'True
  58.       Height          =   492
  59.       Left            =   960
  60.       ScaleHeight     =   465
  61.       ScaleWidth      =   465
  62.       TabIndex        =   0
  63.       Top             =   840
  64.       Width           =   492
  65.    End
  66.    Begin CommandButton btnAbout 
  67.       Caption         =   "About..."
  68.       Height          =   372
  69.       Left            =   3000
  70.       TabIndex        =   8
  71.       Top             =   600
  72.       Width           =   1092
  73.    End
  74.    Begin CommandButton btnOpen 
  75.       Caption         =   "Open..."
  76.       Height          =   372
  77.       Left            =   3000
  78.       TabIndex        =   3
  79.       Top             =   120
  80.       Width           =   1092
  81.    End
  82.    Begin Label lblNumIcons 
  83.       BackColor       =   &H00C0C0C0&
  84.       Height          =   252
  85.       Left            =   1320
  86.       TabIndex        =   5
  87.       Top             =   240
  88.       Width           =   612
  89.    End
  90.    Begin Label lblDumb 
  91.       BackColor       =   &H00C0C0C0&
  92.       Caption         =   "Number of Icons in file:"
  93.       Height          =   492
  94.       Left            =   120
  95.       TabIndex        =   4
  96.       Top             =   120
  97.       Width           =   1092
  98.    End
  99. Dim iconn% 'The current icon number in a file
  100. Dim iconfilename$ 'The filename of the icon file(.EXE, .DLL, .ICO)
  101. Dim numicons% 'The number of icons in a file
  102. Declare Function DrawIcon Lib "user" (ByVal hDC As Integer, ByVal x As Integer, ByVal Y As Integer, ByVal hIcon As Integer) As Integer
  103. 'hDC- Device context of the control to be drawn to
  104. 'x, y- coordinates of where to draw the icon in the control
  105. 'hIcon-Handle of an icon
  106. Declare Function ExtractIcon Lib "shell.dll" (ByVal hinst%, ByVal lpszExeName$, ByVal iIcon%) As Integer
  107. 'hinst- The instance handle of the application calling ExtractIcon.  Should be the name of your EXE file, or VB.EXE at runtime
  108. 'lpszExeName- Module containing icons
  109. 'iIcon%- number of the icon in the file.  If you put -1 for this, it returns the amount of icons in a file
  110. 'The return value should be: 1)An icon handle 2)1 if it's not a EXE, DLL, or ICO file 3)NULL if no icons are in a file
  111. Declare Function GetModuleHandle Lib "Kernel" (ByVal lpModuleName As String) As Integer
  112. 'lpModuleName- The filename of a module, to get the handle of it.
  113. Sub AboutProg ()
  114. End Sub
  115. Sub btnAbout_Click ()
  116. nl$ = Chr$(13) + Chr$(10)
  117. Msg$ = "Icon Extract, Written By Tim Hill (AOL: Tim112)" + nl$ + "Feel free to use this code in your programs." + nl$ + "Tim Hill shall not be responsible in any way for any type of damages incurred to you or your system during the use of this software."
  118. MsgBox Msg$, 64, "Icon Extract"
  119. End Sub
  120. Sub btnCopy_Click ()
  121. pic2.Picture = pic.Image 'Must be pic2.Picture = pic.IMAGE, not pic.Picture, because it is not
  122. 'actually part of the picture yet when you use the API call
  123. End Sub
  124. Sub btnOpen_Click ()
  125. iconfilename$ = InputBox$("Icon File(.ICO,.EXE,.DLL):", "Icon Extract", "PROGMAN.EXE")'Asks for filename
  126. If iconfilename$ = "" Then Exit Sub
  127. pic.Cls'clears the picture box
  128. hModule = GetModuleHandle("C:\VB.EXE")'gets handle
  129. iconmod$ = iconfilename$ + Chr$(0)'prepares filename
  130. Iconh = ExtractIcon(hModule, iconmod$, -1)'gets number of icons
  131. numicons% = Iconh'puts it into a variable
  132. lblNumIcons.Caption = Str$(numicons%)'shows number of icons on label
  133. numicons% = numicons% - 1 'Accounts for the first icon, at number 0
  134. If numicons% > 1 Then 'disables scroll bar if only one or less
  135. hs.Enabled = -1
  136. hs.Enabled = 0
  137. End If
  138. Iconh = ExtractIcon(hModule, iconmod$, 0)'Extracts the first icon
  139. x% = DrawIcon(pic.hDC, 0, 0, Iconh)'Draws the first icon
  140. hs.max = numicons% 'sets maximum scroll bar value to the number of icons
  141. hs.value = 0
  142. End Sub
  143. Sub Command1_Click ()
  144. End Sub
  145. Sub Form_Load ()
  146. AboutProg
  147. End Sub
  148. Sub hs_Change ()
  149. pic.Cls'Clears the picture box
  150. iconn% = hs.value'sets the value of the icon number to the scroll bar position
  151. hModule = GetModuleHandle("C:\VB.EXE")'Gets the module handle
  152. iconmod$ = iconfilename$ + Chr$(0)'prepares filename for ExtractIcon
  153. Iconh = ExtractIcon(hModule, iconmod$, iconn%)'Extracts the specified icon
  154. x% = DrawIcon(pic.hDC, 0, 0, Iconh)'Draws icon
  155. End Sub
  156. Sub up_Click ()
  157. pic.Cls
  158. iconn% = iconn% + 1
  159. If iconn% > dori% Then iconn% = dori%
  160. hModule = GetModuleHandle("C:\VB.EXE")
  161. iconmod$ = "C:\WINDOWS\PROGMAN.EXE" + Chr$(0)
  162. Iconh = ExtractIcon(hModule, iconmod$, iconn%)
  163. x% = DrawIcon(pic.hDC, 0, 0, Iconh)
  164. End Sub
  165.